home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / VSCANF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.0 KB  |  32 lines

  1. /* vscanf.c --- p 481 */
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. void getinput(char *,...);
  5. main()
  6. {
  7.     int accno;
  8.     double price, discount;
  9.         /* call the input routine to read values of variables.
  10.          * First just a single number. Then more than one value. */
  11.     printf("Enter acount number:");
  12.     getinput(" %d", &accno);
  13.     printf("\nEnter price and discount (\%) separated by a space:");
  14.     getinput(" %lf %fl", &price, &discount);
  15.     printf("$%.2f @%.2f%% discount = $%.2f\n", price,
  16.     discount, price*(1.0-discount/100.));
  17. }
  18.                     /*---------------------------------*/
  19.             /* getinput: accepts variable number of arguments
  20.              * and reads formatted values */
  21. void getinput(char *my_format,...)
  22. {
  23.     va_list arg_pointer;
  24.             /* Use va_start macro to get to the start of the
  25.              * variable number of arguments. This will alter the
  26.              * pointer arg_pointer to point to the list of
  27.              * variables to be read. */
  28.     va_start(arg_pointer, my_format);
  29.     vscanf(my_format, arg_pointer);
  30.             /* Use the va_end macro to reset the arg_pointer */
  31.     va_end(arg_pointer);
  32. }